package com.qinge.blog.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qinge.blog.dao.BlogRoleDao;
import com.qinge.blog.entity.BlogRole;
import com.qinge.blog.entity.BlogRoleExample;
import com.qinge.blog.vo.paging.PagingReqVO;
import org.springframework.stereotype.Service;
import com.qinge.blog.service.BlogRoleService;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * @author QDW
 * @date 2022-05-02 23:38:51
 * @description BlogRole service层实现类
 */
@Service
public class BlogRoleServiceImpl  implements BlogRoleService {
    @Resource
    BlogRoleDao roleDao;

    @Override
    public void add(BlogRole... blogRoles) {
        roleDao.batchInsert(Arrays.asList(blogRoles));
    }

    @Override
    public void addByList(List<BlogRole> blogRoles) {
        roleDao.batchInsert(blogRoles);
    }

    @Override
    public void removeById(String id) {
        roleDao.deleteByPrimaryKey(id);
    }

    @Override
    public void removeBatchByIds(List<String> ids) {
        BlogRoleExample example=new BlogRoleExample();
        BlogRoleExample.Criteria criteria=example.createCriteria();

        criteria.andIdIn(ids);

        roleDao.deleteByExample(example);
    }

    @Override
    public void update(BlogRole blogRole) {
        roleDao.upsert(blogRole);
    }

    @Override
    public void upsert(BlogRole blogRole) {
        roleDao.upsert(blogRole);
    }

    @Override
    public BlogRole findById(String id) {
        return roleDao.selectByPrimaryKey(id);
    }

    @Override
    public List<BlogRole> findByIds(List<String> ids) {
        BlogRoleExample example=new BlogRoleExample();
        BlogRoleExample.Criteria criteria=example.createCriteria();

        criteria.andIdIn(ids);

        return roleDao.selectByExample(example);
    }


    @Override
    public PageInfo<BlogRole> findAll() {
        return paging(new PagingReqVO<BlogRole>());
    }

    @Override
    public PageInfo<BlogRole> findAll(PagingReqVO<BlogRole> pagingReqVO) {
        return paging(pagingReqVO);
    }

    @Override
    public PageInfo<BlogRole> paging(PagingReqVO<BlogRole> pagingReqVO) {
        PageHelper.startPage(pagingReqVO);

        BlogRoleExample example=new BlogRoleExample();

        List<BlogRole> list=roleDao.selectByExample(example);

        return new PageInfo<>(list);
    }

}

